package frog.lazy.framework.http.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

public class DoubleSerializer extends JsonSerializer<Double> {
    @Override
    public void serialize(Double value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        BigDecimal d = new BigDecimal(value).setScale(6, BigDecimal.ROUND_HALF_UP);
        gen.writeString(d.toPlainString());
    }
}
